<?php
class WE_Validator_UsernameUniqueOk extends Zend_Validate_Abstract
{
    const INDISPONIBLE = 'usernameUnique';
    const EMPTYNAME = 'usernameEmpty';
    
    protected $_authAdapter;

    protected $_messageTemplates = array(
        self::INDISPONIBLE => '用户名已存在',
    		self::EMPTYNAME => '用户名不能为空'
    );

    public function isValid($username, $context = null)
    {
        if ( empty($username)) {
            $this->_error(self::EMPTYNAME);
            return false;
        } else {
        	
        	$user = new Model_User();

        	if (!$user->isUsernameDispo($username)) {
        		$this->_error(self::INDISPONIBLE);
        		return false;
        	}
        	 
            
        	return true;
        }
    }
    
    public function getAuthAdapter()
    {
        return $this->_authAdapter;
    }
}